package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.entity.DamageList;
import com.atguigu.jxc.entity.DamageListGoods;
import com.atguigu.jxc.entity.OverflowList;
import com.atguigu.jxc.entity.OverflowListGoods;
import com.atguigu.jxc.service.StockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class StockController {

    @Autowired
    private StockService stockService;

    // http://localhost:8080/damageListGoods/save?damageNumber=BS1605766644460（报损单号,前端生成）

    /**
     * 保存报损单
     *
     * @param damageList
     * @param damageListGoodsStr
     * @return
     */
    @PostMapping("damageListGoods/save")
    public ServiceVO damageListGoods(HttpSession session, DamageList damageList, String damageListGoodsStr) {
        stockService.saveDamageListGoods(session, damageList, damageListGoodsStr);
        return new ServiceVO(100, "请求成功");
    }

    // http://localhost:8080/overflowListGoods/save?overflowNumber=BY1605767033015

    /**
     * 新增报溢单
     *
     * @param overflowList
     * @param overflowListGoodsStr
     * @return
     */
    @PostMapping("overflowListGoods/save")
    public ServiceVO overflowListGoods(HttpSession session, OverflowList overflowList, String overflowListGoodsStr) {
        stockService.saveOverflowListGoods(session, overflowList, overflowListGoodsStr);
        return new ServiceVO(100, "请求成功");
    }

    // http://localhost:8080/damageListGoods/list

    /**
     * 报损单查询
     * @param sTime
     * @param eTime
     * @return
     */
    @PostMapping("damageListGoods/list")
    public Map damageListGoods(String sTime, String eTime) {
        Map<String, Object> map = new HashMap<>();
        List<DamageList> damageListList = stockService.damageListGoods(sTime,eTime);
        map.put("rows",damageListList);
        return map;
    }

    // http://localhost:8080/damageListGoods/goodsList

    /**
     * 查询报损单商品信息
     * @param damageListId
     * @return
     */
    @PostMapping("damageListGoods/goodsList")
    public Map getDamageListGoodsList(Integer damageListId){
        Map<String, Object> map = new HashMap<>();
        List<DamageListGoods> damageListGoodsList = stockService.getDamageListGoodsList(damageListId);
        map.put("rows",damageListGoodsList);
        return map;
    }

    // http://localhost:8080/overflowListGoods/list

    /**
     * 报溢单查询
     * @param sTime
     * @param eTime
     * @return
     */
    @PostMapping("overflowListGoods/list")
    public Map overflowListGoods(String sTime, String eTime){
        Map<String, Object> map = new HashMap<>();
        List<OverflowList> overflowListList = stockService.overflowListGoods(sTime,eTime);
        map.put("rows",overflowListList);
        return map;
    }

    //http://localhost:8080/overflowListGoods/goodsList
    @PostMapping("overflowListGoods/goodsList")
    public Map getOverflowListGoodsList(Integer overflowListId){
        Map<String, Object> map = new HashMap<>();
        List<OverflowListGoods> overflowListGoodsList = stockService.getOverflowListGoodsList(overflowListId);
        map.put("rows",overflowListGoodsList);
        return map;
    }
}
